package org.nbict.iot.task.realtime.func;

import com.alibaba.fastjson.JSONObject;
import org.apache.storm.trident.operation.BaseFunction;
import org.apache.storm.trident.operation.TridentCollector;
import org.apache.storm.trident.tuple.TridentTuple;
import org.apache.storm.tuple.Values;

/**
 * Created by songseven on 18/6/26.
 */
public class RealtimeResolver extends BaseFunction {

    private static final String[] tags = {"01", "02", "03", "04", "05", "06", "07", "08", "09"};

    @Override
    public void execute(TridentTuple tuple, TridentCollector collector) {
//        String platform_id = tuple.getString(0);
//        String car_vin = tuple.getString(1);
//        Long timestamp = tuple.getLong(3);
        JSONObject upload = (JSONObject) tuple.get(3); //info

        Values values = new Values();
        //1, 2, 3, 4, 5, 6, 7, 8, 9
//        for (String tag : upload.keySet()) {
//            values.add(upload.get(tag));
//        }
        for (int i = 0; i < 9; i++) {
            values.add(upload.get(tags[i]));
        }
        collector.emit(values);
    }
}
